/*
 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
 * Licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include "string.h"
#include "test_crypto_api_types.h"
#include "tee_log.h"

AlgMapInfo g_algMapList[] = {
    // Symmetric Crypto
    {
        .algName = "SC_aes_ecb_nopad",
        .algValue = TEE_ALG_AES_ECB_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_des_ecb_nopad",
        .algValue = TEE_ALG_DES_ECB_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_des3_ecb_nopad",
        .algValue = TEE_ALG_DES3_ECB_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_ecb_pkcs5",
        .algValue = TEE_ALG_AES_ECB_PKCS5,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_sm4_ecb_nopad",
        .algValue = TEE_ALG_SM4_ECB_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_cbc_nopad",
        .algValue = TEE_ALG_AES_CBC_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_ctr",
        .algValue = TEE_ALG_AES_CTR,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_cts",
        .algValue = TEE_ALG_AES_CTS,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_xts",
        .algValue = TEE_ALG_AES_XTS,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 2,
        .needKeyCount = 2,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_des_cbc_nopad",
        .algValue = TEE_ALG_DES_CBC_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_des3_cbc_nopad",
        .algValue = TEE_ALG_DES3_CBC_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_aes_cbc_pkcs5",
        .algValue = TEE_ALG_AES_CBC_PKCS5,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_sm4_cbc_nopad",
        .algValue = TEE_ALG_SM4_CBC_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_sm4_ctr",
        .algValue = TEE_ALG_SM4_CTR,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
        {
        .algName = "SC_sm4_cbc_pkcs7",
        .algValue =  TEE_ALG_SM4_CBC_PKCS7,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    {
        .algName = "SC_sm4_cfb128",
        .algValue = TEE_ALG_SM4_CFB128,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "SC",
        .algOperaClassValue = TEE_OPERATION_CIPHER,
    },
    // Ae encrypt
    {
        .algName = "AE_aes_ccm",
        .algValue = TEE_ALG_AES_CCM,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "AE",
        .algOperaClassValue = TEE_OPERATION_AE,
    },
    {
        .algName = "AE_aes_gcm",
        .algValue = TEE_ALG_AES_GCM,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "AE",
        .algOperaClassValue = TEE_OPERATION_AE,
    },
    {
        .algName = "AE_sm4_gcm",
        .algValue = TEE_ALG_SM4_GCM,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "AE",
        .algOperaClassValue = TEE_OPERATION_AE,
    },
    // Mac
    {
        .algName = "M_aes_cbc_nopad",
        .algValue = TEE_ALG_AES_CBC_MAC_NOPAD,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_aes_cbc_pkcs5",
        .algValue = TEE_ALG_AES_CBC_MAC_PKCS5,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_aes_cmac",
        .algValue = TEE_ALG_AES_CMAC,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_des_cbc_nopad",
        .algValue = TEE_ALG_DES_CBC_MAC_NOPAD,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_des_cbc_pkcs5",
        .algValue = TEE_ALG_DES_CBC_MAC_PKCS5,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_des3_cbc_nopad",
        .algValue = TEE_ALG_DES3_CBC_MAC_NOPAD,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_des3_cbc_pkcs5",
        .algValue = TEE_ALG_DES3_CBC_MAC_PKCS5,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_md5",
        .algValue = TEE_ALG_HMAC_MD5,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sha1",
        .algValue = TEE_ALG_HMAC_SHA1,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sha224",
        .algValue = TEE_ALG_HMAC_SHA224,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sha256",
        .algValue = TEE_ALG_HMAC_SHA256,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sha384",
        .algValue = TEE_ALG_HMAC_SHA384,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sha512",
        .algValue = TEE_ALG_HMAC_SHA512,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    {
        .algName = "M_hmac_sm3",
        .algValue = TEE_ALG_HMAC_SM3,
        .fwdMode = TEE_MODE_MAC,
        .bckMode = TEE_MODE_MAC,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_MAC,
    },
    // Asymmetric-Encrypt
    {
        .algName = "AS_ed_rsa_v15",
        .algValue = TEE_ALG_RSAES_PKCS1_V1_5,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "M",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha1",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha224",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha256",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha256",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha384",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_oaep_sha512",
        .algValue = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_rsa_nopad",
        .algValue = TEE_ALG_RSA_NOPAD,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    {
        .algName = "AS_ed_sm2_pke",
        .algValue = TEE_ALG_SM2_PKE,
        .fwdMode = TEE_MODE_ENCRYPT,
        .bckMode = TEE_MODE_DECRYPT,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASEn",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_CIPHER,
    },
    // Asymmetric-Signature
    {
        .algName = "AS_sv_rsa_v15_md5",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_MD5,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_v15_sha1",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_SHA1,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_v15_sha224",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_SHA224,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_v15_sha256",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_SHA256,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_v15_sha384",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_SHA384,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_v15_sha512",
        .algValue = TEE_ALG_RSASSA_PKCS1_V1_5_SHA512,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_MD5",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_MD5,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_SHA1",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_SHA224",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_SHA256",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_SHA384",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_rsa_pss_SHA512",
        .algValue = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ecdsa_sha1",
        .algValue = TEE_ALG_ECDSA_SHA1,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ecdsa_sha224",
        .algValue = TEE_ALG_ECDSA_SHA224,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ecdsa_sha256",
        .algValue = TEE_ALG_ECDSA_SHA256,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ecdsa_sha384",
        .algValue = TEE_ALG_ECDSA_SHA384,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ecdsa_sha512",
        .algValue = TEE_ALG_ECDSA_SHA512,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_ed25519",
        .algValue = TEE_ALG_ED25519,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    {
        .algName = "AS_sv_sm2_dsa_sm3",
        .algValue = TEE_ALG_SM2_DSA_SM3,
        .fwdMode = TEE_MODE_SIGN,
        .bckMode = TEE_MODE_VERIFY,
        .operaKeyCount = 1,
        .needKeyCount = 1,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "ASSg",
        .algOperaClassValue = TEE_OPERATION_ASYMMETRIC_SIGNATURE,
    },
    // Derive
    {
        .algName = "DR_ecdh",
        .algValue = TEE_ALG_ECDH_DERIVE_SHARED_SECRET,
        .fwdMode = TEE_MODE_DERIVE,
        .bckMode = TEE_MODE_DERIVE,
        .operaKeyCount = 1,
        .needKeyCount = 2,
        .isSwitchFwdBckOperaKey = 1,
        .algOperaClassName = "DR",
        .algOperaClassValue = TEE_OPERATION_KEY_DERIVATION,
    },
    {
        .algName = "DR_dh",
        .algValue = TEE_ALG_DH_DERIVE_SHARED_SECRET,
        .fwdMode = TEE_MODE_DERIVE,
        .bckMode = TEE_MODE_DERIVE,
        .operaKeyCount = 1,
        .needKeyCount = 2,
        .isSwitchFwdBckOperaKey = 1,
        .algOperaClassName = "DR",
        .algOperaClassValue = TEE_OPERATION_KEY_DERIVATION,
    },
    {
        .algName = "DR_x25519",
        .algValue = TEE_ALG_X25519,
        .fwdMode = TEE_MODE_DERIVE,
        .bckMode = TEE_MODE_DERIVE,
        .operaKeyCount = 1,
        .needKeyCount = 2,
        .isSwitchFwdBckOperaKey = 1,
        .algOperaClassName = "DR",
        .algOperaClassValue = TEE_OPERATION_KEY_DERIVATION,
    },
    // Digest
    {
        .algName = "DI_md5",
        .algValue = TEE_ALG_MD5,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sha1",
        .algValue = TEE_ALG_SHA1,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sha224",
        .algValue = TEE_ALG_SHA224,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sha256",
        .algValue = TEE_ALG_SHA256,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sha384",
        .algValue = TEE_ALG_SHA384,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sha512",
        .algValue = TEE_ALG_SHA512,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
    {
        .algName = "DI_sm3",
        .algValue = TEE_ALG_SM3,
        .fwdMode = TEE_MODE_DIGEST,
        .bckMode = TEE_MODE_DIGEST,
        .operaKeyCount = 0,
        .needKeyCount = 0,
        .isSwitchFwdBckOperaKey = 0,
        .algOperaClassName = "DI",
        .algOperaClassValue = TEE_OPERATION_DIGEST,
    },
};
size_t g_algMapListSize = sizeof(g_algMapList) / sizeof(g_algMapList[0]);

AlgMapInfo *FindAlgMapInfo(char *algName)
{
    size_t i;
    for (i = 0; i < g_algMapListSize; i++) {
        if (strcmp((const char *)algName, (const char *)g_algMapList[i].algName) == 0) {
            return &(g_algMapList[i]);
        }
    }
    return NULL;
}

KeyTypeMapInfo g_keyTypeMap[] = {
    /*        keyTypeName,                        keyType */
    {
        .keyTypeName = {"kt_aes"},
        .keyType = TEE_TYPE_AES,
        .keyGenType = TEE_TYPE_AES,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_des"},
        .keyType = TEE_TYPE_DES,
        .keyGenType = TEE_TYPE_DES,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_des3"},
        .keyType = TEE_TYPE_DES3,
        .keyGenType = TEE_TYPE_DES3,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_md5"},
        .keyType = TEE_TYPE_HMAC_MD5,
        .keyGenType = TEE_TYPE_HMAC_MD5,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sha1"},
        .keyType = TEE_TYPE_HMAC_SHA1,
        .keyGenType = TEE_TYPE_HMAC_SHA1,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sha224"},
        .keyType = TEE_TYPE_HMAC_SHA224,
        .keyGenType = TEE_TYPE_HMAC_SHA224,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sha256"},
        .keyType = TEE_TYPE_HMAC_SHA256,
        .keyGenType = TEE_TYPE_HMAC_SHA256,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sha384"},
        .keyType = TEE_TYPE_HMAC_SHA384,
        .keyGenType = TEE_TYPE_HMAC_SHA384,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sha512"},
        .keyType = TEE_TYPE_HMAC_SHA512,
        .keyGenType = TEE_TYPE_HMAC_SHA512,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_rsa_pub"},
        .keyType = TEE_TYPE_RSA_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_RSA_KEYPAIR,
        .needGenParams = NEED_RSA_EXP_MAYBE,
    },
    {
        .keyTypeName = {"kt_rsa_pair"},
        .keyType = TEE_TYPE_RSA_KEYPAIR,
        .keyGenType = TEE_TYPE_RSA_KEYPAIR,
        .needGenParams = NEED_RSA_EXP_MAYBE,
    },
    {
        .keyTypeName = {"kt_dsa_pub"},
        .keyType = TEE_TYPE_DSA_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_DSA_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_dsa_pair"},
        .keyType = TEE_TYPE_DSA_KEYPAIR,
        .keyGenType = TEE_TYPE_DSA_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_dh_pair"},
        .keyType = TEE_TYPE_DH_KEYPAIR,
        .keyGenType = TEE_TYPE_DH_KEYPAIR,
        .needGenParams = NEED_DH_BASE_PRIME_XBITS,
    },
    {
        .keyTypeName = {"kt_gn_sec"},
        .keyType = TEE_TYPE_GENERIC_SECRET,
        .keyGenType = TEE_TYPE_GENERIC_SECRET,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_data"},
        .keyType = TEE_TYPE_DATA,
        .keyGenType = TEE_TYPE_DATA,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_data_1_1"},
        .keyType = TEE_TYPE_DATA_GP1_1,
        .keyGenType = TEE_TYPE_DATA_GP1_1,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_ecdsa_pub"},
        .keyType = TEE_TYPE_ECDSA_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_ECDSA_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_ecdsa_pair"},
        .keyType = TEE_TYPE_ECDSA_KEYPAIR,
        .keyGenType = TEE_TYPE_ECDSA_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_ecdh_pub"},
        .keyType = TEE_TYPE_ECDH_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_ECDH_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_ecdh_pair"},
        .keyType = TEE_TYPE_ECDH_KEYPAIR,
        .keyGenType = TEE_TYPE_ECDH_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_ed25519_pub"},
        .keyType = TEE_TYPE_ED25519_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_ED25519_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_ed25519_pair"},
        .keyType = TEE_TYPE_ED25519_KEYPAIR,
        .keyGenType = TEE_TYPE_ED25519_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_x25519_pub"},
        .keyType = TEE_TYPE_X25519_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_X25519_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = "kt_x25519_keypair",
        .keyType = TEE_TYPE_X25519_KEYPAIR,
        .keyGenType = TEE_TYPE_X25519_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = "kt_sm2_dsa_pub",
        .keyType = TEE_TYPE_SM2_DSA_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_SM2_DSA_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_sm2_dsa_pair"},
        .keyType = TEE_TYPE_SM2_DSA_KEYPAIR,
        .keyGenType = TEE_TYPE_SM2_DSA_KEYPAIR,
        .needGenParams = NEED_GEN_ECC_CURVE,
    },
    {
        .keyTypeName = {"kt_sm2_kep_pub"},
        .keyType = TEE_TYPE_SM2_KEP_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_SM2_KEP_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_sm2_kep_pair"},
        .keyType = TEE_TYPE_SM2_KEP_KEYPAIR,
        .keyGenType = TEE_TYPE_SM2_KEP_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = "kt_sm2_pke_pub",
        .keyType = TEE_TYPE_SM2_PKE_PUBLIC_KEY,
        .keyGenType = TEE_TYPE_SM2_PKE_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_sm2_pke_pair"},
        .keyType = TEE_TYPE_SM2_PKE_KEYPAIR,
        .keyGenType = TEE_TYPE_SM2_PKE_KEYPAIR,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = {"kt_hmac_sm3"},
        .keyType = TEE_TYPE_HMAC_SM3,
        .keyGenType = TEE_TYPE_HMAC_SM3,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
    {
        .keyTypeName = "kt_sm4",
        .keyType = TEE_TYPE_SM4,
        .keyGenType = TEE_TYPE_SM4,
        .needGenParams = NEED_NO_GEN_PARAMS,
    },
};
uint32_t g_keyTypeMapSize = sizeof(g_keyTypeMap) / sizeof(g_keyTypeMap[0]);

KeyTypeMapInfo *FindKeyTypeValue(char *keyTypeName)
{
    size_t i;
    for (i = 0; i < g_keyTypeMapSize; i++) {
        if (strcmp((const char *)keyTypeName, (const char *)g_keyTypeMap[i].keyTypeName) == 0) {
            return &(g_keyTypeMap[i]);
        }
    }
    return NULL;
}